﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework; // Vector2 e demais classes para posicionamento.
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace first_project
{
    class Shot
    {
        /// <summary>
        /// Shot Direction
        /// </summary>
        private Vector2 direction;

        public Rectangle CollisionRect
        {
            get { return new Rectangle((int)position.X, (int)position.Y, this.image.Width, this.image.Height); }
        }

        /// <summary>
        /// Shot Speed
        /// </summary>
        private Vector2 speed;

        private Vector2 position;
        public Vector2 Position
        {
            get
            {
                return position;
            }

            set
            {
                position = value;
            }

        }

        /// <summary>
        /// Damage of shot
        /// </summary>
        private float damage;
        public float Damage
        {
            get
            {
                return damage;
            }

            set
            {
                damage = value;

                if (damage >= 5)
                {
                    damage = 5;
                }

                else if (damage <= 1)
                {
                    damage = 1;
                }
            }
        }


        /// <summary>
        /// Image of Shot
        /// </summary>
        private Texture2D image;


        private GameWindow Window;
        ShotDistanceTraveled shotDistance;
        bool shotDelete;

        public Shot(Texture2D image, GameWindow Window,Vector2 speed, Vector2 direction, Vector2 position)
        {
            this.image = image;
            this.Window = Window;
            this.speed = speed;
            this.direction = direction;
            this.position = position;
            shotDistance = new ShotDistanceTraveled(Window, position);
            shotDelete = false;
        }

        public void Update(GameTime gameTime)
        {
            position += speed * direction;
            shotDelete = shotDistance.CheckDistance(speed*direction);
            

            if (Position.X >= Window.ClientBounds.Width + image.Width / 2)
            {
                position.X = -image.Width / 2;
            }
            else if (Position.X <= -image.Width / 2)
            {
                position.X = Window.ClientBounds.Width + image.Width / 2;
            }
            else if (Position.Y >= Window.ClientBounds.Height + image.Height / 2)
            {
                position.Y = -image.Height / 2;
            }
            else if (Position.Y <= -image.Height / 2)
            {

                position.Y = Window.ClientBounds.Height + image.Height / 2;
            }
         
        }

        public bool isShotDeleted()
        {
            if (shotDelete)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(image, position, null, Color.White, 0.0f, new Vector2(image.Width/2,image.Height/2), 0.2f, SpriteEffects.None, 0);
 
        }
    }
}
